home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DBPCXL15.ARJ / SRC_C.ARJ / PCX8.C < prev   
C/C++ Source or Header  |  1992-01-26  |  4KB  |  110 lines

  1. /* pcxlib.c  : A .PCX file decoder */
  2. #include <stdio.h>
  3. #include <io.h>
  4. #include <conio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <alloc.h>
  8. #include <mem.h>
  9. #include <dos.h>
  10. #include <errno.h>
  11.  
  12. #include "vidlib.h"   /* used in fdisp8PCX() */
  13. #include "vesa.h"
  14. #include "pcxlib.h"
  15.  
  16. /*/////////////////////////////////////////////////////////////////////////
  17. //  int =fdisp8PCX       uses extern symbols _screen_start, _screen_width,
  18. //    -1 on exit       _screen_length and _memory_length defined in vidlib.h
  19. ///////////////////////////////////////////////////////////////////////////*/
  20. int   fdisp8PCX(unsigned dx, unsigned dy,
  21.                 unsigned x0, unsigned y0, unsigned x1, unsigned y1, PCXF *p)
  22. {
  23.    unsigned int vdy,lastdy;
  24.    char *dest;
  25.  
  26.    if (pcxdebug) {
  27.       fprintf(pcxdebug,"fdisp8PCX(%u, %u,  %u, %u,  %u, %u, %Fp). PCXerror=%i\n",
  28.                        dx,dy,x0,y0, x1, y1, p, PCXerror);
  29.    }
  30.    if ( BIOScrtmode == 0x13 ) {
  31.       return(fread8PCX( _screen_start, _screen_width, _memory_length,
  32.                         dx,dy,x0,y0,x1,y1,p));
  33.    } else { /* must be VESA mode, use buffers */
  34.       lastdy=y1-y0+dy;
  35.       while (y0 < y1+1) {
  36.      VESAsetpage(VESAwhat_page(dy,dx));
  37.      dest=(char *)normalize((char *)(0xA0000000L+VESApage_offset(dy,dx)));
  38.          /* vdy=number of lines to do */
  39.      if (lastdy > Vnext_break_row)
  40.         vdy=Vnext_break_row-dy;
  41.          else
  42.             vdy=lastdy-dy;
  43.          if (fread8PCX( dest, _screen_width, vdy, 0, 0,  x0, y0,
  44.                     x1, y0+vdy-1, p) < 1) {
  45.             return(-1);
  46.          }
  47.          y0+=vdy; dy+=vdy;
  48.          if ( y0 < y1+1 ) {
  49.             if (fread8PCX(p->buffer, _screen_width, 1, 0, 0, x0, y0,
  50.                            x1, y0, p) < 1) {
  51.                 return(-1);
  52.             }
  53.             VESAdisp256(dx, dy, p->buffer, _screen_width, 16,
  54.                                 0, 0, x1-x0+1, 1,1);
  55.             if (pcxdebug)
  56.                fprintf(pcxdebug,"VESAdisp256(dx=%u, dy=%u, p->b=%Fp, _s_w=%u,"
  57.                                 " 16, 0, 0, sdx=%u, 1, 1)\n",
  58.                                 dx, dy, p->buffer,_screen_width, x1-x0+1);
  59.             y0++; dy++;
  60.          }
  61.       } /* end while VESA loop */
  62.    }
  63.    return(1);
  64. }
  65.  
  66. /*/////////////////////////////////////////////////////////////////////////
  67. //  int =fread8PCX
  68. //    -1 on error
  69. ///////////////////////////////////////////////////////////////////////////*/
  70. int   fread8PCX(char *d, unsigned dw, unsigned dl, unsigned dx, unsigned dy,
  71.                 unsigned x0, unsigned y0, unsigned x1, unsigned y1, PCXF *p)
  72. {
  73.     int s;
  74.     char *dest;
  75.  
  76.     if (pcxdebug) {
  77.         fprintf(pcxdebug,"fread8PCX(%Fp, %u, %u,  %u, %u, "
  78.                       " %u, %u,  %u, %u,  %Fp).\n",
  79.                       d, dw, dl, dx, dy, x0, y0, x1, y1, p);
  80.     }
  81.     if ( (y1-y0+1 > dl-dy) || (x1-x0+1 > dw-dx) ||
  82.        (dy > dl-1) || (dx > dw-1) ||
  83.          (x0 > x1) || (x1+1 > p->w) ||
  84.          (y0 > y1) || (y1+1 > p->l) ) {
  85.        PCXerror=EINVAL;
  86.        return(-1);
  87.     }
  88.  
  89.     /* seek to first scan line to be read */
  90.     if (fseekPCX(p, y0) == -1) {
  91.        PCXerror=EINVDAT;
  92.        return(-1);
  93.     }
  94.  
  95.     if (pcxdebug) {
  96.        fprintf(pcxdebug,"   fseekPCX(p,%u) -> ftell(p)=%li\n",
  97.                         y0, ftell(p->fp));
  98.     }
  99.     /* there! */
  100.     dest=(char *)normalize(d + dy*dw + dx);
  101.     for ( s=y0; s <= y1; s++) {
  102.         if ( ((s%16) == 0) && (s > 15))
  103.            *(p->marks + (s/16-1))=ftell(p->fp);
  104.         _read_pcx_line( p, dest, x0, x1);
  105.     dest=(char *)normalize(dest+dw);
  106.     }
  107.     return( s );  /* return next scan line to read */
  108. }
  109.  
  110.